package com.tongyi.lizhishop.activitys;

import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.LogUtils;
import com.tongyi.lizhishop.beans.BillItemDetailBean;
import com.tongyi.lizhishop.common.CommonObserver;

import com.tongyi.lizhishop.R;
import com.tongyi.lizhishop.api.MessageApi;
import com.tongyi.lizhishop.common.MultiStatusActivity;
import com.tongyi.lizhishop.managers.APIServiceManager;
import com.tongyi.lizhishop.utils.AppStringUtils;

import butterknife.BindView;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class ConsumeItemDetailActivity extends MultiStatusActivity {

    @BindView(R.id.ddbh)
    TextView ddbh;
    @BindView(R.id.xdsj)
    TextView xdsj;
    @BindView(R.id.ddje)
    TextView ddje;
    @BindView(R.id.syhb)
    TextView syhb;
    @BindView(R.id.sjdz)
    TextView sjdz;
    @BindView(R.id.dzkh)
    TextView dzkh;
    @BindView(R.id.activity_consume_item_detail)
    LinearLayout activityConsumeItemDetail;
    private String bilid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initTitleBarView(titlebar, "详细");
        bilid = getIntent().getExtras().getString("bilid");
        multipleStatusView.showLoading();
        loadData();
    }

    private void loadData() {

        APIServiceManager.getInstance().create(MessageApi.class)
                .infoBill(bilid)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new CommonObserver<BillItemDetailBean>() {
                    @Override
                    public void onSuccess(BillItemDetailBean value) {
                        LogUtils.w(value);
                        multipleStatusView.showContent();
                        BillItemDetailBean.ArrayBean arrayBean = value.getArray();
                        bindView(arrayBean);
                    }

                    @Override
                    public void onFailure(Throwable e) {
                        showError("无法连接网络", 0, multipleStatusView);
                    }
                });
    }

    private void bindView(BillItemDetailBean.ArrayBean arrayBean) {
        ddbh.setText(arrayBean.getBil_order()); //订单编号
        xdsj.setText(AppStringUtils.getSafeTime("yyyy-MM-dd HH:mm:ss", arrayBean.getBil_starttime()));//下单时间
        ddje.setText(arrayBean.getBil_money());//订单金额
        syhb.setText(arrayBean.getBil_card());//使用红包
        sjdz.setText(arrayBean.getBil_smoneyall());//实际到账
        dzkh.setText(arrayBean.getBil_cardid());//使用卡号
    }

    @Override
    public int getContentView() {
        return R.layout.activity_consume_item_detail;
    }
}
